#ifdef WITH_OPENGL
#pragma once
#include "opengl.h"

namespace krryn{
namespace system_imp{
	template<typename _Desc, bool _Bind = _Desc::position_type::m_Available>
	class bind_position_opengl{
	public:
		typedef typename _Desc::position_type type;

		void bind(context_opengl &a_Context){
			a_Context.enable(GL_VERTEX_ARRAY);

			glVertexPointer(
				type::m_Size, GL_FLOAT, 
				_Desc::m_TotalSize, _Desc::m_PositionOffset);
		}
	};

	template<typename _Desc>
	class bind_position_opengl<_Desc, false>{
	public:
		void bind(context_opengl &a_Context){
			std::clog << "Disabled position" << std::endl;
		}
	};

	template<typename _Desc, bool _Bind = _Desc::color_type::m_Available>
	class bind_color_opengl{
	public:
		typedef typename _Desc::color_type type;

		void bind(context_opengl &a_Context){
			a_Context.enable(GL_COLOR_ARRAY);

			glColorPointer(
				type::m_Size, GL_FLOAT,
				_Desc::m_TotalSize, (GLbyte*)0 + _Desc::m_ColorOffset);
		}
	};

	template<typename _Desc>
	class bind_color_opengl<_Desc, false>{
	public:
		void bind(context_opengl &a_Context){
			a_Context.disable(GL_COLOR_ARRAY);
		}
	};

	template<typename _Desc, bool _Bind = _Desc::normal_type::m_Available>
	class bind_normal_opengl{
	public:
		typedef typename _Desc::normal_type type;

		void bind(context_opengl &a_Context){
			a_Context.enable(GL_NORMAL_ARRAY);

			glNormalPointer(
				GL_FLOAT, _Desc::m_TotalSize, (GLbyte*)0 + _Desc::m_NormalOffset);
		}
	};

	template<typename _Desc>
	class bind_normal_opengl<_Desc, false>{
	public:
		void bind(context_opengl &a_Context){
			a_Context.disable(GL_NORMAL_ARRAY);
		}
	};

	template<typename _Desc, bool _Bind = _Desc::uv_type::m_Available>
	class bind_uv_opengl{
	public:
		void bind(context_opengl &a_Context){
			size_t l_UVOffset = _Desc::m_UVOffset;

			for(size_t i = 0; i < _Desc::m_TexCoords; i++){
				size_t l_Count = _Desc::uv_type::coord_count(i);

				if(l_Count != 0){
					a_Context.enable_texture(i);
					glTexCoordPointer(
						(GLint)l_Count, 
						GL_FLOAT,
						_Desc::m_TotalSize, 
						(GLbyte*)0 + l_UVOffset);

					l_UVOffset += sizeof(float) * l_Count;
				}
			}

			/// disable everything form m_TexCoords to MAX_TEXT_COORDS
		}
	};

	template<typename _Desc>
	class bind_uv_opengl<_Desc, false>{
	public:
		void bind(context_opengl &a_Context){
			//for(size_t i = 0; i < _Desc::m_TexCoords; i++){
			// disable max textures
			//	a_Context.disable_texture(i);
			//}
		}
	};
}
}
#endif